#include "BasicSpi.h"
#include <wiringPi.h>
#include <wiringPiSPI.h>
CBasicSpi::CBasicSpi(int port, int speed, int spiMode)
{
	port &= 1;
	m_nSpiPort = port;
	m_nSpeed = speed;
	m_nSpiMode = spiMode;
}

void CBasicSpi::begin()
{
	wiringPiSPISetupMode(m_nSpiPort, m_nSpeed, m_nSpiMode);
}

int CBasicSpi::write(unsigned char *buf, int len)
{
	return wiringPiSPIDataRW(m_nSpiPort, buf, len);
}

int CBasicSpi::write(unsigned char data)
{
	return write(&data, 1);
}

int CBasicSpi::misoPin()
{
	return m_nSpiPort == 0 ? 13 : -1;  // wiringPi
}
